<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('我的出租记录列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>房屋名称：</label>
                                <input type="text" name="houHouse.name"/>
                            </li>
                            <li>
                                <label>借出状态：</label>
                                <select name="rentStatus">
                                    <option value="">所有</option>
                                    <option value="1">正常出租</option>
                                    <option value="2">已逾期</option>
                                    <option value="3">已退房</option>
                                </select>
                            </li>
                            <li>
                                <label>起始日期：</label>
                                <input type="text" class="time-input" placeholder="请选择租房起始日期" name="startTime"/>
                            </li>
                            <li>
                                <label>终止日期：</label>
                                <input type="text" class="time-input" placeholder="请选择预定终止日期" name="endTime"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="admin:record:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="admin:record:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('admin:record:edit')}]];
        var removeFlag = [[${@permission.hasPermi('admin:record:remove')}]];
        var prefix = ctx + "admin/record";

        $(function() {
            var options = {
                url: prefix + "/listWithDetail/2",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "租房记录",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'recordId',
                    title: '租房记录唯一标识',
                    visible: false
                },
                {
                    field: 'rentStatus',
                    title: '租赁状态',
                    formatter: function (value, row, index) {
                        if (row.rentStatus == 1) {
                            return '<strong>正常出租</strong>';
                        } else if (row.rentStatus == 2) {
                            return '<strong>已逾期</strong>';
                        } else if (row.rentStatus == 3) {
                            return '<strong>已退房</strong>';
                        }
                    },
                    cellStyle: function (value, row, index) {
                        if (row.rentStatus == 1) {
                            return {
                                css: {
                                    'color': '#ff9409'
                                }
                            };
                        } else if (row.rentStatus == 2) {
                            return {
                                css: {
                                    'color': '#cb1711'
                                }
                            };
                        } else if (row.rentStatus == 3) {
                            return {
                                css: {
                                    'color': '#037203'
                                }
                            };
                        }
                    }
                },
                {
                    field: 'houHouse.name',
                    title: '房屋名称'
                },
                {
                    field: 'sysUser.userName',
                    title: '租户名称'
                },
                {
                    field: 'startTime',
                    title: '租房起始日期'
                },
                {
                    field: 'endTime',
                    title: '预定终止日期'
                },
                {
                    field: 'price',
                    title: '总价'
                },
                {
                    field: 'contract',
                    title: '合同附件',
                    align: "center",
                    formatter: function(value, row, index) {
                        let a = '';
                        if(row.contract != null){
                            a = '<a onclick="aaa(\''+row.contract+'\')"><i class="fa fa-file-excel-o"></i></a>';
                        }
                      return a;
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.status != 2){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="tuifang(\'' + row.recordId + '\')">退房</a> ');
                            actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="goCheckout(\'' + row.recordId + '\')">延期</a> ');
                        }
                        actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="goUpload(\'' + row.recordId + '\')">上传</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        //附件下载
        function aaa(contract){
            window.location.href = ctx + "common/download/resource?resource=" +contract;
        }

        //租客退房
        function tuifang(recordId){
            $.modal.confirm("确认要为该租客退房吗？", function() {
                $.operate.post(prefix + "/edit", { "recordId": recordId, "status": 2 });
            })
        }

        //租期延长
        function goCheckout(id) {
            var url = ctx + 'admin/record/goCheckout/'+ id;
            $.modal.open("选择延长时间" , url);
        }

        //租期延长
        function goUpload(id) {
            var url = ctx + 'admin/record/goUpload/'+ id;
            $.modal.open("选择文件" , url);
        }
    </script>
</body>
</html>